<template>
  <view class="content">
    <view class="btn" @tap="addOrder">
      <image src="../../static/img/Slice 50.png" mode=""></image>
      <span>创建商单</span>
    </view>
    <view class="btn" @tap="addCard">
      <image src="../../static/img/Slice 50.png" mode=""></image>
      <span>创建达人名片</span>
    </view>

    <view class="toastBox" v-if="toast">
      <image src="../../static/img/Slice 51.png" mode=""></image>
      <view class="">
        已经有
      </view>
      <view class="">
        达人名片了
      </view>
    </view>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        toast: false,
        state: '',
        create_card: '',
        create_order:''
      };
    },
    onShow() {
      this.get_card_state()
      this.get_user_info()
    },
    methods: {
      // 获取创建达人名片状态
      async get_card_state() {
        const {
          data: res
        } = await uni.$http.post('create_anchor_card/get_card_state')
        this.state = res.data.state
      },
      // 获取用户信息
      async get_user_info() {
        const {
          data: res
        } = await uni.$http.post('user/get_user_info')
        this.create_order = res.data.create_order
        this.create_card = res.data.create_card
      },
      addOrder() {
        if (this.create_order != 1) {
          uni.showToast({
            title: '当前身份无法创建商单，请前往个人中心修改身份 ',
            icon: 'none'
          });
          return
        }
        uni.navigateTo({
          url: '/pages/addOrder/addOrder'
        })
      },
      async addCard() {
        if (this.create_card != 1) {
          uni.showToast({
            title: '当前身份无法创建名片，请前往个人中心修改身份',
            icon: 'none'
          });
          return
        }
        const res = await uni.$http.post('create_anchor_card/get_card_state')
        this.state = res.data.data.state
        if (this.state == 0) {
          uni.navigateTo({
            url: '/pages/people/chuangjiandaren'
          })
        } else if (this.state == 1) {
          this.toast = true
          setTimeout(() => {
            this.toast = false
          }, 1500)
        }
      }
    }
  }
</script>

<style lang="scss">
  .content {
    min-height: 100vh;
    background-color: #F2F3F6;
    padding-top: 104rpx;

    .btn {
      margin: 0 auto;
      display: flex;
      align-items: center;
      width: 542rpx;
      height: 100rpx;
      background: #7D81A9;
      box-shadow: 0rpx 8rpx 16rpx 0rpx rgba(0, 0, 0, 0.1);
      border-radius: 200rpx;
      font-size: 32rpx;
      font-family: PingFang SC-Semibold, PingFang SC;
      font-weight: 600;
      color: #FFFFFF;
      margin-bottom: 52rpx;

      image {
        width: 48rpx;
        height: 48rpx;
        margin-right: 32rpx;
        margin-left: 80rpx;
      }
    }

    .toastBox {
      margin: 194rpx auto;
      box-sizing: border-box;
      border-radius: 10rpx;
      width: 220rpx;
      height: 220rpx;
      background: #000;
      opacity: 0.8;
      font-size: 28rpx;
      font-family: PingFang SC-Regular, PingFang SC;
      font-weight: 400;
      color: #FFFFFF;
      text-align: center;
      padding-top: 23rpx;

      image {
        width: 76rpx;
        height: 76rpx;
      }
    }
  }
</style>